<import template="/admin/_header" />
<import template="/admin/_content" />

<div class="page-title">
    <div class="title-env">
        <h1 class="title">系统设置</h1>
        <p class="description">系统相关设置，部分设置请小心修改。</p>
    </div>
    <div class="breadcrumb-env">
        <ol class="breadcrumb bc-1">
            <li><a href="/admin"><i class="fa fa-home"></i>管理端</a></li>
            <li><a href="/admin/setting">系统设置</a></li>
        </ol>
    </div>
</div>
<section class="content">
    <div class="row">
        <div class="col-sm-6 col-md-6 col-lg-6">
            <div class="box">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">套餐自定义</h3>
                        <div class="panel-options">
                            <a href="javascript:;" id="setting-save" data-form-id="setting-form">
                                <i class="fa fa-save"></i>
                            </a>
                            <a href="javascript:;" data-toggle="reload">
                                <i class="fa fa-rotate-right"></i>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <form id="setting-form" name="setting-form" action="/admin/setting/savePlanCustom.json">
                            <table cellspacing="0" class="table table-small-font table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>套餐类型</th>
                                        <th>对应名称</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <if condition="count($custom_plan_name) > 0">
                                    <loop variable="$custom_plan_name" key="$key" value="$name">
                                        <tr id="setting-{$key}">
                                            <td>{$key}</td>
                                            <td><input class="form-control" name="setting-{$key}" value="{$name}"/></td>
                                        </tr>
                                    </loop>
                                </if>
                                </tbody>
                            </table>
                            </form>
                        </div>
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
        <div class="col-sm-6 col-md-6 col-lg-6">
            <div class="box">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">套餐流量</h3>
                        <div class="panel-options">
                            <a href="javascript:;" id="transfer-save" data-form-id="transfer-form">
                                <i class="fa fa-save"></i>
                            </a>
                            <a href="javascript:;" data-toggle="reload">
                                <i class="fa fa-rotate-right"></i>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <form id="transfer-form" name="transfer-form" action="/admin/setting/saveTransfer.json">
                            <table cellspacing="0" class="table table-small-font table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>套餐类型</th>
                                    <th>流量/GB</th>
                                </tr>
                                </thead>
                                <tbody>
                                <if condition="count($custom_transfer_level) > 0">
                                    <loop variable="$custom_transfer_level" key="$key" value="$name">
                                        <tr id="transfer-{$key}">
                                            <td>{$key}</td>
                                            <td><input class="form-control" name="transfer-{$key}" value="{$name}"/></td>
                                        </tr>
                                    </loop>
                                </if>
                                </tbody>
                            </table>
                            </form>
                        </div>
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
    </div>

    <div class="row">
        <div class="col-sm-6 col-md-6 col-lg-6">
            <div class="box">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">其他定义</h3>
                        <div class="panel-options">
                            <a href="javascript:;" id="other-save" data-form-id="other-form">
                                <i class="fa fa-save"></i>
                            </a>
                            <a href="javascript:;" data-toggle="reload">
                                <i class="fa fa-rotate-right"></i>
                            </a>
                        </div>
                    </div>
                    <div class="panel-body">
                        <div class="table-responsive">
                            <form id="other-form" name="other-form" action="/admin/setting/saveOther.json">
                                <table cellspacing="0" class="table table-small-font table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th width="200px">#</th>
                                            <th>值</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>新用户注册邮箱验证</td>
                                            <td>
                                                <input type="checkbox" name="mail_verify" value="1" class="iswitch-lg iswitch-info" <if condition="$mail_verify == 1">checked</if>>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>套餐卡充值时间叠加</td>
                                            <td>
                                                <input type="checkbox" name="custom_transfer_repeat" value="1" class="iswitch-lg iswitch-info" <if condition="$custom_transfer_repeat == 1">checked</if>>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>签到流量最大值(MB)</td>
                                            <td><input class="form-control" name="check_transfer_max" value="{$check_transfer_max}"/></td>
                                        </tr>
                                        <tr>
                                            <td>签到流量最小值(MB)</td>
                                            <td><input class="form-control" name="check_transfer_min" value="{$check_transfer_min}"/></td>
                                        </tr>
                                        <tr>
                                            <td>测试用户试用时长(天)</td>
                                            <td><input class="form-control" name="user_test_day" value="{$user_test_day}"/></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </div>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
    </div>
</section>
</div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function($) {


        $("#setting-save,#transfer-save,#other-save").on('click', function(){
            var formName = $(this).attr('data-form-id');

            var form = $("form#"+formName);
            $.ajax({
                url: form.attr('action'),
                data: form.serialize(),
                type: "POST",
                dataType: "json",
                success: function(result) {
                    if(result.code != 200) {
                        showToastr(result.message, 0, 3000, '系统错误');
                        return;
                    }
                    showToastr(result.data.message, 0, 3000, '提示');
                },
                error: function(jqXhr) {

                }
            });
        });
    });
</script>
<import template="/admin/_footer" />
